
import 'package:baby/UI/Widgets/HtmlContent/TransformUnit.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:html/dom.dart' as pre;

import '../HtmlContent.dart';

class TagImg extends TransformUnit<HtmlContentState, Object> {
  @override
  void execution(context, data) {
    if (data is pre.Element && data.localName == "img") {
      var imgUrl = data.attributes["src"];
      if (imgUrl == null) return;

      var condition = imgUrl.startsWith("http://");
      condition |= imgUrl.startsWith("https://");

      if (!condition){
        imgUrl = "${context.widget.baseUrl.toString()}/$imgUrl";
      }

      pipeLineContext.processWith(CachedNetworkImage(imageUrl: imgUrl, placeholder: (context, url) => Container(
        color: Color(0x09000000),
      ),));
    }
  }
}